package com.tcd.web.controller;


import com.tcd.pojo.Role;
import com.tcd.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 角色表 前端控制器
 * </p>
 *
 * @author space
 * @since 2021-05-21
 */
@RestController
@RequestMapping("/permission/role")
@CrossOrigin
public class RoleController {
    @Autowired
    RoleService roleService;

    @RequestMapping("/getRoles")
    public List<Role> getRolesFilter(@RequestParam(defaultValue = "1") Integer pageIndex, @RequestParam(defaultValue = "10") Integer pageSize, String name, Integer permissionId) {
        return roleService.getRoleFilter(pageIndex,pageSize,name,permissionId);
    }

    @RequestMapping("/getRolesCount")
    public Integer getRolesCount(String name, Integer permissionId) {
        return roleService.getRoleFilterCount(name,permissionId);
    }

    @RequestMapping("/addRole")
    public Integer addRole(@RequestBody Role role){
        return roleService.addRole(role);
    }

    @RequestMapping("/updateRole")
    public Integer updateRole(@RequestBody Role role){
        return roleService.updateRole(role);
    }

    @RequestMapping("/delRoles")
    public Integer delRoles(Integer[] ids){
        return roleService.delRoles(ids);
    }

    @RequestMapping("/setRolePermission")
    public Integer setRolePermission(Integer roleId, Integer[] permissionIds){
        return roleService.setRolePermission(roleId,permissionIds);
    }
}

